// udpconner project udpconner.go
package udpconner

import (
	"errors"
	"hostlink/hostlink_udp/udpconn"
	"strings"

	"github.com/astaxie/beego/config"
)

type UdpPool struct {
	udpconn.Pool
}

func (this *UdpPool) Setup(conf config.Configer) (err error) {
	host := conf.String("source_address")
	localhost := conf.String("local_address")
	if host == "" || localhost == "" {
		err = errors.New("The address of server is empty.")
		return
	}
	ss := strings.Split(host, ";")
	this.Address = ss[0]
	this.CurrentAddress = this.Address
	if len(ss) > 1 {
		this.Bak = ss[1]
	} else {
		this.Bak = this.Address
	}
	this.LocalAddress = localhost
	this.SetSize(conf.DefaultInt("max_conn_pool_num", 1))
	err = this.Initialize()
	return
}
